package com.hibernate;

import java.util.Date;
import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 	* A data access object (DAO) providing persistence and search support for Facture entities.
 			* Transaction control of the save(), update() and delete() operations 
		can directly support Spring container-managed transactions or they can be augmented	to handle user-managed Spring transactions. 
		Each of these methods provides additional information for how to configure it for the desired type of transaction control. 	
	 * @see com.hibernate.Facture
  * @author MyEclipse Persistence Tools 
 */

public class FactureDAO extends BaseHibernateDAO  {
	     private static final Logger log = LoggerFactory.getLogger(FactureDAO.class);
		//property constants
	public static final String NOMFACTURE = "nomfacture";
	public static final String PRENOMFACTURE = "prenomfacture";
	public static final String ADRESSEFACTURE = "adressefacture";
	public static final String VILLEFACTURE = "villefacture";
	public static final String TELEPHONEFACTURE = "telephonefacture";
	public static final String EMAILFACTURE = "emailfacture";
	public static final String METHODEFACTURE = "methodefacture";
	public static final String NUMEROCARTEFACTURE = "numerocartefacture";
	public static final String CODEVERIFICATIONFACTURE = "codeverificationfacture";
	public static final String MONTANTFACTURE = "montantfacture";



    
    public void save(Facture transientInstance) {
        log.debug("saving Facture instance");
        try {
            getSession().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	public void delete(Facture persistentInstance) {
        log.debug("deleting Facture instance");
        try {
            getSession().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public Facture findById( java.lang.Integer id) {
        log.debug("getting Facture instance with id: " + id);
        try {
            Facture instance = (Facture) getSession()
                    .get("com.hibernate.Facture", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    public List findByExample(Facture instance) {
        log.debug("finding Facture instance by example");
        try {
            List results = getSession()
                    .createCriteria("com.hibernate.Facture")
                    .add(Example.create(instance))
            .list();
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }    
    
    public List findByProperty(String propertyName, Object value) {
      log.debug("finding Facture instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from Facture as model where model." 
         						+ propertyName + "= ?";
         Query queryObject = getSession().createQuery(queryString);
		 queryObject.setParameter(0, value);
		 return queryObject.list();
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
	}

	public List findByNomfacture(Object nomfacture
	) {
		return findByProperty(NOMFACTURE, nomfacture
		);
	}
	
	public List findByPrenomfacture(Object prenomfacture
	) {
		return findByProperty(PRENOMFACTURE, prenomfacture
		);
	}
	
	public List findByAdressefacture(Object adressefacture
	) {
		return findByProperty(ADRESSEFACTURE, adressefacture
		);
	}
	
	public List findByVillefacture(Object villefacture
	) {
		return findByProperty(VILLEFACTURE, villefacture
		);
	}
	
	public List findByTelephonefacture(Object telephonefacture
	) {
		return findByProperty(TELEPHONEFACTURE, telephonefacture
		);
	}
	
	public List findByEmailfacture(Object emailfacture
	) {
		return findByProperty(EMAILFACTURE, emailfacture
		);
	}
	
	public List findByMethodefacture(Object methodefacture
	) {
		return findByProperty(METHODEFACTURE, methodefacture
		);
	}
	
	public List findByNumerocartefacture(Object numerocartefacture
	) {
		return findByProperty(NUMEROCARTEFACTURE, numerocartefacture
		);
	}
	
	public List findByCodeverificationfacture(Object codeverificationfacture
	) {
		return findByProperty(CODEVERIFICATIONFACTURE, codeverificationfacture
		);
	}
	
	public List findByMontantfacture(Object montantfacture
	) {
		return findByProperty(MONTANTFACTURE, montantfacture
		);
	}
	

	public List findAll() {
		log.debug("finding all Facture instances");
		try {
			String queryString = "from Facture";
	         Query queryObject = getSession().createQuery(queryString);
			 return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
    public Facture merge(Facture detachedInstance) {
        log.debug("merging Facture instance");
        try {
            Facture result = (Facture) getSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(Facture instance) {
        log.debug("attaching dirty Facture instance");
        try {
            getSession().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(Facture instance) {
        log.debug("attaching clean Facture instance");
        try {
            getSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
}